% % File		:	verity/ppg_0_1_display
% % Description	:   for Heart Rate Algorithm
% % Fuction		:	PPG signal display
% % Author		:	@hiyangdong
% % Version		:	V0.1
% % Time		:	12 Jan. 2016

%{
 1.0.1 read data and orignal calculate
%}
% close all
clear all

ExcelName = 'ppg_RawData.xlsx';
ExcelSheet = 14;

data_type = 8;
data_sheet_max = 14;
time_length = 60;
data_length  = time_length * 100;

data.all = zeros(data_type,data_length,data_sheet_max);

for i = 1:data_type
	xlRange_code = ['A'+i-1,':','A'+i-1];
    xlRange = char(xlRange_code);
    data.all(i,:,ExcelSheet) = xlsread(ExcelName,ExcelSheet,xlRange);
end

num_data = data.all(1,:,ExcelSheet);
ppg_data = data.all(2,:,ExcelSheet);
ppg_data = ppg_data -mean(ppg_data);
gyro.x   = data.all(3,:,ExcelSheet);
gyro.y   = data.all(4,:,ExcelSheet);
gyro.z   = data.all(5,:,ExcelSheet);
acce.x   = data.all(6,:,ExcelSheet);
acce.y   = data.all(7,:,ExcelSheet);
acce.z   = data.all(8,:,ExcelSheet);

ppg_size = length(ppg_data);
sampletime = 0.01;                               %sample time that unit is second
t = 0:sampletime:(ppg_size-1) * sampletime;     %time point

figure(1);clf();subplot(2,1,1);
plot(t,ppg_data,'k');
title('Time domain orignal PPG data');

samplefreq = 1/sampletime;                        %sample frequency that unit is Hz
f = (0:(ppg_size-1))/ppg_size*samplefreq;           %frequency point
fft_data=fft(ppg_data);
fft_data_abs=abs(fft_data);

figure(1);subplot(2,1,2);
plot(f,fft_data_abs,'k');
title('Frequency domain orignal PPG data ');

mat_filename = 'ppg_RawDataSheet';
mat_filename = strcat(mat_filename,num2str(ExcelSheet),'.mat');
save(mat_filename);

disp('end');